package huisu.onClass.class01.exer03;

import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    private static final int MAX_X = 8;
    private static final int MAX_Y = 4;

    private static final int[][] NEXT_POS = {{1, 2}, {2, 1}, {2, -1}, {1, -2}};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkedList<int[]> curPath = new LinkedList<>();
        LinkedList<LinkedList<int[]>> allPaths = new LinkedList<>();
        curPath.add(new int[] {0, 0});
        dfs(curPath, allPaths, 0, 0);
        for (int i = 0; i < allPaths.size(); i++) {
            LinkedList<int[]> cur = allPaths.get(i);
            System.out.print("0,");
            for (int j = 0; j < cur.size() - 1; j++) {
                System.out.print(cur.get(j)[0] + "->" + cur.get(j + 1)[1] + ",");
            }
            System.out.println(8);
        }
    }

    private static void dfs(LinkedList<int[]> curPath, LinkedList<LinkedList<int[]>> allPaths, int curX, int curY) {
        if (curX == MAX_X && curY == MAX_Y) {
            // end
            allPaths.add(new LinkedList<>(curPath));
            return;
        }
        for (int i = 0; i < 4; i++) {
            int nextX = curX + NEXT_POS[i][0];
            int nextY = curY + NEXT_POS[i][1];
            if (nextX >= 0 && nextX <= MAX_X && nextY >= 0 && nextY <= MAX_Y) {
                curPath.add(new int[] {nextX, nextY});
                dfs(curPath, allPaths, nextX, nextY);
                curPath.removeLast();
            }
        }
    }
}
